package infaraway.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by :Infaraway
 * DATE : 2017/4/25
 * Time : 23:33
 * Funtion :
 */
public class WeatherData implements Subject{

    private List<Observer> observerList;
    private String temperature;
    private String humidity;
    private String pressure;

    public WeatherData() {
        this.observerList = new ArrayList<>();
    }

    @Override
    public void registerObserver(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    public void notifyObserver() {
        for (Observer observer : observerList) {
            observer.updateNotify(temperature, humidity, pressure);
        }
    }

    public void updateValue(){
        notifyObserver();
    }

    /**
     * 当天气状态改变，改变各种参数值
     * @param temperature：温度
     * @param humidity：湿度
     * @param pressure：气压
     */
    public void setValue(String temperature, String humidity, String pressure){
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        updateValue();
    }
}
